// ----------------------------------------------整体-----------------------------------

import Cookie from './cookie.js'
import Api from  './api.js'
import WApi from  '../wj/api.js'
import Base_api from "./Base_api.js";


new Vue({
    el:'#management',
    data(){
        return{
            ManaShow:[],                             //报名人
            carezh:[],                              //关注的账号
            fanszh:[],                              //账号的粉丝
            uinfos:[],                              //当前用户
            aid:'',                     //------当前选中的饭局aid
            search:'',                  //------搜索框内容
            Info:'',                    //个人简介
            Zy:'',                      //职业
            City:'',                    //城市
            Title:'',                   //活动标题
            Img:'',                     //饭局图片
            Lb_name:'',                 //饭局类型
            WanFa:'',                   //玩法
            Text:'',                    //饭局介绍
        }
    },
    methods:{
        //获取个人信息
        async info () {
            let zh = sessionStorage.getItem("zh")
            let allinfo = await WApi.login()
            for(let i=0;i<allinfo.length;i++){
                if(allinfo[i].zh==zh){
                    this.uinfos=allinfo[i]
                    break
                }
            }
            //调用关注表的内容
            let careinfo = await WApi.careInfo()
            let caremsg = careinfo.data
            //获取
            for (let i=0;i<caremsg.length;i++){
                for (let j=0;j<allinfo.length;j++){
                    //关注的账号
                    if(caremsg[i].user_zh==zh){
                        if(caremsg[i].care_zh==allinfo[j].zh){
                            this.carezh.push(allinfo[j])
                        }
                    }
                    //粉丝的账号
                    if(caremsg[i].care_zh==zh){
                        if(caremsg[i].user_zh==allinfo[j].zh){
                            this.fanszh.push(allinfo[j])
                        }
                    }
                }
            }
            this.aid = Cookie.getCookie("aid")                          //------获取当前选中的饭局aid
            let activitying = Api.getActivitying(this.uinfos.id,this.aid)          //返回当前选中的管理饭局信息（单个）
            this.initData(activitying)                                      //------初始化赋值
            this.ManaShow = Base_api.getManaShow(this.uinfos.id,this.aid)
        },
        initData(activitying){                              //---------进行姓名、昵称、头像的赋值------------
            this.Title = activitying.title
            this.Img = activitying.img
            this.Lb_name = activitying.lb_name
            this.WanFa = activitying.wanfa
            this.Text = activitying.text
        },
        choose(index,userid,fanjuid){
            let show = document.getElementById(index)
            let Button1 = document.getElementById(index+8080)
            let Button2 = document.getElementById(index+9090)
            if(show.style.visibility=="hidden"){
                if(Button2.className=="button btn-reset"){
                    this.$alert('已经拒绝了', '警告', {
                        confirmButtonText: '确定',
                    });
                }else if(Button2.className=="button btn-choose"){
                    this.$confirm('是否要选择？', '确认信息', {
                        distinguishCancelAndClose: true,
                        confirmButtonText: '是',
                        cancelButtonText: '否'
                    })
                        .then(() => {
                            this.$message({
                                type: 'info',
                                message: '选择成功'
                            });
                            show.style.visibility="visible"
                            Button1.className="button btn-reset"
                            // Button1.disabled="disabled"
                            Base_api.updateCode(userid,fanjuid,0)
                        })
                        .catch(action => {
                            this.$message({
                                type: 'info',
                                message: action === 'cancel'
                                    ? '放弃保存并离开页面'
                                    : '停留在当前页面'
                            })
                        });
                }
            }else {
                show.style.visibility="hidden"
                Button1.className="button btn-choose"
            }
        },
        choose2(index,userid,fanjuid){
            let Button1 = document.getElementById(index+8080)
            let Button2 = document.getElementById(index+9090)
            if(Button2.className=="button btn-reset"){
                Button2.className="button btn-choose"
            }else {
                if(Button1.className=="button btn-reset"){
                    this.$alert('已经选择了', '警告', {
                        confirmButtonText: '确定',
                    });
                }else {
                    this.$confirm('是否要选择拒绝？', '确认信息', {
                        distinguishCancelAndClose: true,
                        confirmButtonText: '是',
                        cancelButtonText: '否'
                    })
                        .then(() => {
                            this.$message({
                                type: 'info',
                                message: '拒绝成功'
                            });
                            Button2.className="button btn-reset"
                            Button2.disabled="disabled"
                            Base_api.updateCode(userid,fanjuid,2)
                        })
                        .catch(action => {
                            this.$message({
                                type: 'info',
                                message: action === 'cancel'
                                    ? '放弃保存并离开页面'
                                    : '停留在当前页面'
                            })
                        });
                }
            }
        }
    },
    mounted() {
        if(sessionStorage.getItem("zh")==null){
            this.$alert('请先登录', '系统提示', {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'warning',
                        message: '即将跳转到登录界面...'
                    });
                    location.href='./login.html'
                }
            });
        }else{
            this.info()
        }
    }
})

